// 获取订单id
var content_url = window.location.href;
content_url = content_url.split("?");
var orderId= content_url[ content_url.length-1 ].split("=")[ content_url[ content_url.length-1 ].split("=").length-1 ];
console.log(orderId);
// 支付方式
var payType="";

$(".pay_way .ali").click(function(){
    $(this).attr("data_way","ali");
})
$(".pay_way .wei").click(function(){
    $(this).attr("data_way","wei");
})
$(".pay_way img").click(function(){
    $(this).css("border","2px solid #FF5D5B").siblings().attr("data_way","").css("border","2px solid transparent");
    payType=$(this).attr("data_way");
    $(".pay_btn .lf").html("");
})
// 提交订单
$(".paynow").click(function(){
    console.log(payType);
    $.ajax({
        url:url+"v1/order/pay",
        dataType:"json",
        method:"post",
        data:{
            token:localStorage.token,
            payType:payType,
            orderId:orderId
        },
        xhrFields: {
            withCredentials: true // 允许跨域名储存和访问cookie
        }
    }).done(function(data){
        console.log(data);
        if(data.code=="success"){
            alert("支付成功")
            window.location.href="payList.html";
        }else if(data.code=="param_incomplete"){
            $(".pay_btn .lf").html("请选择一种支付方式");
        }else if(data.code=="order_pay_fail"){
            $(".pay_btn .lf").html("订单支付失败，请刷新后再试");
        }else if(data.code=="account_token_invalid"){
            $(".pay_btn .lf").html("身份已失效,请重新登陆");
        }else{
            $(".pay_btn .lf").html(data.message);
        }

    })
})